package com.xry.service.impl;

import com.xry.annotation.LogMethod;
import com.xry.bean.Brand;
import com.xry.mapper.BrandDao;
import com.xry.mapper.ProductDao;
import com.xry.service.BrandService;
import com.xry.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    BrandDao brandDao;
    @Autowired
    ProductDao productDao;
    @Override
    @LogMethod(serviceName = "增加品牌信息")
    public Brand add(Brand brand) {
        //新增数据
        brandDao.add(brand);
        //通过主键查询数据库中的数据
        Brand result = brandDao.one(brand.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "删除品牌信息")
    @Transactional
    public int del(Integer id) {
        productDao.delByBrand(id);
        return brandDao.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改品牌信息")
    public Brand edit(Brand brand) {
        brandDao.edit(brand);
        Brand result=brandDao.one(brand.getId());
        return result;
    }

    @Override
    public List<Brand> all(Brand brand) {
        return brandDao.all( brand);
    }

    @Override
    public Brand one(Integer id) {
        return brandDao.one(id);
    }

    @Override
    public void page(Page page, Brand brand){
        int count=brandDao.pageCount(brand);
        Object data=brandDao.page(page,brand);
        page.setCount(count);
        page.setData(data);
    }
}
